package com.link.base.base.wechat.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.link.base.base.accnt.dao.mybatis.mapper.AccountMapper;
import com.link.base.base.accnt.model.Account;
import com.link.base.base.coupons.model.Coupons;
import com.link.base.base.wechat.dao.mybatis.mapper.ArticlesMapper;
import com.link.base.base.wechat.model.Messageresult;
import com.link.base.wechat.mpnews.model.Article;
import com.link.base.wechat.mpnews.model.NewsItem;
import com.link.base.wechat.basic.util.WeixinHttpUtil;
import com.link.core.cllog.LCLogger;
import com.link.base.wechat.mpnews.service.ArticleService;
import com.link.base.wechat.payment.util.PayUtils;
import com.link.base.wechat.wxcard.model.*;
import com.link.base.wechat.wxcard.util.WxCardUtil;
import com.link.base.wechat.wxplatform.model.WxPlatform;
import com.link.base.wechat.wxplatform.service.WxPlatformService;
import com.link.base.wechat.wxtoken.service.WxTokenService;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.ServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.util.*;
import com.link.base.wechat.wxcard.model.*;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 微信图文素材实现类
 *
 * @author lujiang
 */
@Service
public class ArticlesServiceImpl extends BasicServiceImpl<Article> implements ArticlesService {
    @Resource
    private WxImageService wxImageService;

    @Resource
    private WxTokenService wxTokenService;

    @Resource
    private ArticleService articleService;

    @Resource
    private Environment env;

    /**
     *  6.获取永久素材(下载)
     */
    private static final String GET_PERMANENT_MATERIAL_URL = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=ACCESS_TOKEN";

    @Resource
    private ArticlesMapper articlesMapper;
    @Resource
    private ArticlesService articlesService;

    @Resource
    private AccountMapper accountMapper;

    @Resource
    private WxPlatformService wxPlatformService;

    @Resource
    private MessageresultService messageresultService;

    @Override
    public BasicMapper<Article> getBasicMapper() {
        return articlesMapper;
    }

    @Override
    public Map<String, Object> deletePermanentMaterial(String accessToken, String mediaId) throws Exception {
        // 1.准备好json请求参数
        Map<String, String> paramMap = new HashMap<String, String>(16);
        paramMap.put("media_id", mediaId);
        Object data = JSON.toJSON(paramMap);
        // 2.准备好请求url
        String url = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=" + accessToken;
        // 3.发起HTTP请求，获取返回结果
        JSONObject jsonObject = WeixinHttpUtil.doPost(url, data);
        LCLogger.info().withMessageKey("deletePermanentMaterial")
                .withMessage("jsonObject:" + jsonObject.toJSONString()).flush();
        // 4.解析结果
        JSONObject returnJsonObject = null;
        String errcode = "errcode";
        if (jsonObject != null) {
            // 4.1 错误消息处理
            if (jsonObject.getInteger(errcode) != 0) {
                int errCode = jsonObject.getInteger("errcode");
                String errMsg = jsonObject.getString("errmsg");
                LCLogger.error().withMessageKey("deletePermanentMaterial")
                        .withMessage("删除永久素材失败 " + "errcode:" + errCode + ", errmsg:" + errMsg).flush();
                // 4.2 新增成功
            } else {
                LCLogger.info().withMessageKey("deletePermanentMaterial")
                        .withMessage("删除永久素材成功 ").flush();
                returnJsonObject = jsonObject;
            }
        }
        Map<String, Object> map = new HashMap<String, Object>(16);
        map.put("errcode", jsonObject.getInteger("errcode"));
        map.put("returnJsonObject", jsonObject);
        return map;
    }

    @Override
    public BaseInfo getBaseInfo(Coupons wxCoupon) throws Exception {
        BaseInfo baseInfo = new BaseInfo();
        WxPlatform wxPlatform = new WxPlatform();
        wxPlatform.setId(wxCoupon.getWeChatId());
        wxPlatform = wxPlatformService.queryById(wxPlatform);
        // 微信服务器上的url
        baseInfo.setLogoUrl(wxPlatform.getHeadImg());
        // 具体门店
        baseInfo.setBrandName(wxPlatform.getWx_pp_accntname());
        // 二维码
        baseInfo.setCodeType("CODE_TYPE_QRCODE");
        baseInfo.setTitle(wxCoupon.getCouponsName());
        baseInfo.setColor(wxCoupon.getCardColor());
        baseInfo.setNotice(wxCoupon.getCondit());
        baseInfo.setDescription(wxCoupon.getInstru());
        DateInfo dateInfo = new DateInfo();
        dateInfo.setType("DATE_TYPE_FIX_TIME_RANGE");
        //有效期设置
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Long begin = (Long)((format.parse(wxCoupon.getEffectStaTime()).getTime()
                - format.parse("1970-01-01").getTime()) / 1000);
        Long end = (Long)((format.parse(wxCoupon.getEffectEndTime()).getTime()
                - format.parse("1970-01-01").getTime()) / 1000);
        dateInfo.setBeginTimestamp(begin);
        dateInfo.setEndTimestamp(end);
        dateInfo.setFixedBeginTerm(0);
        dateInfo.setFixedTerm(wxCoupon.getEffetDay());
        baseInfo.setDateInfo(dateInfo);
        Sku sku = new Sku();
        sku.setQuantity(wxCoupon.getCouponsNum());
        baseInfo.setSku(sku);
        baseInfo.setGetLimit(wxCoupon.getLimitGet());
        String flag = "Y";
        if (flag.equals(wxCoupon.getGain())) {
            baseInfo.setCanGiveFriend(true);
        } else {
            baseInfo.setCanGiveFriend(false);
        }
        if (flag.equals(wxCoupon.getPageShare())) {
            baseInfo.setCanShare(true);
        } else {
            baseInfo.setCanShare(false);
        }
        //使用自定义code
//        baseInfo.setUse_custom_code(true);
        return baseInfo;
    }

    @Override
    public AdvancedInfo getAdvancedInfo(Coupons wxCoupon) throws Exception {
        UseCondition condition = new UseCondition();
        condition.setAcceptCategory(wxCoupon.getFitProd());
        condition.setLeastCost((double) wxCoupon.getAmountLimit() * 100);
        condition.setObjectUseFor(wxCoupon.getFitProd());
        AdvancedInfo advancedInfo = new AdvancedInfo();
        advancedInfo.setUseCondition(condition);

        String url = wxImageService.queryById(wxCoupon.getCoverPicId()).getTempMaterialUrl();
        advancedInfo.setIconUrlList(url);
        return advancedInfo;
    }

    @Override
    public Map<String, Object> getMap(Coupons wxCoupon, BaseInfo baseInfo, AdvancedInfo advancedInfo) throws Exception {
        List<String> iconUrlList = new ArrayList<String>();
        //优惠券类型由 CashCoupon 转为 CASH （微信端只认CASH）
        if ("CashCoupon".equals(wxCoupon.getCouponsType())) {
            wxCoupon.setCouponsType("CASH");
        }
        //兑换券类型转换
        String giftCoupon = "GiftCoupon";
        if (giftCoupon.equals(wxCoupon.getCouponsType())) {
            wxCoupon.setCouponsType("GIFT");
        }
        iconUrlList.add(advancedInfo.getIconUrlList());
        Map<String, Object> abstractMap = new HashMap<>(16);
        abstractMap.put("icon_url_list",iconUrlList);
        Map<String, Object> advancedInfoMap = new HashMap<>(16);
        advancedInfoMap.put("abstract",abstractMap);
        advancedInfoMap.put("use_condition",advancedInfo.getUseCondition());
        Map<String, Object> cardTypeMap = new HashMap<>(16);
        cardTypeMap.put("base_info", baseInfo);
        cardTypeMap.put("advanced_info", advancedInfoMap);
        String groupon = "GROUPON";
        //现金
        String cash = "CASH";
        //折扣
        String discount = "DISCOUNT";
        //礼物
        String gift = "GIFT";
        //会员卡
        String memberCard = "MEMBER_CARD";
        if (groupon.equals(wxCoupon.getCouponsType())) {
            cardTypeMap.put("deal_detail", wxCoupon.getCouponsCont());
        } else if (cash.equals(wxCoupon.getCouponsType())) {
            //单位为分
            Integer amountLimit = wxCoupon.getAmountLimit() * 100;
            cardTypeMap.put("least_cost", amountLimit);
            Double disAmount = wxCoupon.getDisAmount() * 100;
            cardTypeMap.put("reduce_cost", disAmount);
        } else if (discount.equals(wxCoupon.getCouponsType())) {
            cardTypeMap.put("discount", wxCoupon.getDisRate());
        } else if (gift.equals(wxCoupon.getCouponsType())) {
            cardTypeMap.put("gift", wxCoupon.getCouponsCont());
            //会员卡类型
        } else if (memberCard.equals(wxCoupon.getCouponsType())) {
            setMemberCard(cardTypeMap,wxCoupon);
        }
        Map<String, Object> cardMap = new HashMap<>(16);
        if (groupon.equals(wxCoupon.getCouponsType())) {
            cardMap.put("card_type", "GROUPON");
            cardMap.put("groupon", cardTypeMap);
        } else if (cash.equals(wxCoupon.getCouponsType())) {
            cardMap.put("card_type", "CASH");
            cardMap.put("cash", cardTypeMap);
        } else if (discount.equals(wxCoupon.getCouponsType())) {
            cardMap.put("card_type", "DISCOUNT");
            cardMap.put("discount", cardTypeMap);
        } else if (gift.equals(wxCoupon.getCouponsType())) {
            cardMap.put("card_type", "GIFT");
            cardMap.put("gift", cardTypeMap);
        } else if (memberCard.equals(wxCoupon.getCouponsType())) {
            cardMap.put("card_type", "MEMBER_CARD");
            cardMap.put("member_card", cardTypeMap);
        }
        //成功之后，恢复优惠券类型原有独立源代码。
        String cash1 = "CASH";
        if (cash1.equals(wxCoupon.getCouponsType())) {
            wxCoupon.setCouponsType("CashCoupon");
        }
        if (gift.equals(wxCoupon.getCouponsType())) {
            wxCoupon.setCouponsType("GiftCoupon");
        }
        return cardMap;
    }

    /**
     * 会员卡特有字段
     *
     * @author 路江
     * @date 2018-05
     * @param cardTypeMap
     * @param wxCoupon
     */
    public void  setMemberCard(Map<String, Object> cardTypeMap,Coupons wxCoupon) throws Exception {
        //商家自定义会员卡背景图
        WxPlatform wxPlatform = new WxPlatform();
        wxPlatform.setId(wxCoupon.getWeChatId());
        cardTypeMap.put("background_pic_url",wxPlatformService.queryById(wxPlatform).getHeadImg());
        //显示积分填写true或false，如填写true，积分相关字段均为 必 填 若设置为true则后续不可以被关闭。
        cardTypeMap.put("supply_bonus",wxCoupon.getSupplyBonus());
        //是否支持储值，填写true或false。如填写true，储值相关字段均为 必 填
        // 若设置为true则后续不可以被关闭。该字段须开通储值功能后方可使用， 详情见： 获取特殊权限
        cardTypeMap.put("supply_balance",wxCoupon.getSupplyBalance());
        //会员卡特权说明,限制1024汉字 必输
        cardTypeMap.put("prerogative",wxCoupon.getPrerogative());
        //设置为true时用户领取会员卡后系统自动将其激活，无需调用激活接口，详情见 自动激活。不必输
        cardTypeMap.put("auto_activate",wxCoupon.getAutoActivate());
        //自定义会员信息类目，会员卡激活后显示,包含name_type (name) 和url字段
        CustomField customField1 = new CustomField();
        customField1.setUrl(wxCoupon.getCustomFieldUrl());
        customField1.setNameType(wxCoupon.getCustomFieldNameType());
        cardTypeMap.put("custom_field1",customField1);
        //激活会员卡的url
        cardTypeMap.put("activate_url",wxCoupon.getActivateUrl());
        //自定义会员信息类目，会员卡激活后显示。
        CustomCell customCell1 = new CustomCell();
        customCell1.setName(wxCoupon.getCustomCellName());
        customCell1.setTips(wxCoupon.getCustomCellTips());
        customCell1.setUrl(wxCoupon.getCustomCellUrl());
        cardTypeMap.put("custom_cell1",customCell1);
        //积分规则 非必输
        BonusRule bonusRule = new BonusRule();
        bonusRule.setCostMoneyUnit(wxCoupon.getCostMoneyUnit());
        bonusRule.setIncreaseBonus(wxCoupon.getIncreaseBonus());
        bonusRule.setMaxIncreaseBonus(wxCoupon.getMaxIncreaseBonus());
        bonusRule.setInitIncreaseBonus(wxCoupon.getInitIncreaseBonus());
        bonusRule.setCostBonusUnit(wxCoupon.getCostBonusUnit());
        bonusRule.setReduceMoney(wxCoupon.getReduceMoney());
        bonusRule.setLeastMoneyToUseBonus(wxCoupon.getLeastMoneyToUseBonus());
        bonusRule.setMaxReduceBonus(wxCoupon.getMaxReduceBonus());

        cardTypeMap.put("bonus_rule",bonusRule);
        //折扣，该会员卡享受的折扣优惠,填10就是九折。 非必输
        cardTypeMap.put("discount",wxCoupon.getDiscount());
    }

    @Override
    public Map<String, Object> createWxCard(Coupons wxCoupon) {
        Map<String, Object> resultMap = new HashMap<>(16);
        BaseInfo baseInfo;
        try {
            // 获取卡卷基本信息
            baseInfo = articlesService.getBaseInfo(wxCoupon);
            // 获取高级卡卷信息
            AdvancedInfo advancedInfo = articlesService.getAdvancedInfo(wxCoupon);
            Map<String, Object> cardMap = new HashMap<>(16);
            // 按照格式生成map
            cardMap = articlesService.getMap(wxCoupon, baseInfo, advancedInfo);
            Map<String, Object> card = new HashMap<>(16);
            card.put("card", cardMap);
            //从lnk_wx_platform 取出 token ,token会有微信授权模块去进行更新

            WxPlatform wxPlatform = new WxPlatform();
            wxPlatform.setId(wxCoupon.getWeChatId());
            WxPlatform platform = wxPlatformService.queryById(wxPlatform);
            String accessToken = wxTokenService.getWxAccessTokenByAppId(platform.getWx_app_id()).getAccess_token();
            Gson gson = new Gson();
            // 转换成特定格式字符串
            String data = WxCardUtil.getJsonData(card);
            Map<String,Object> result = WxCardUtil.createWxCard(accessToken,"NEW",data);
            //卡片主键
            String cardId = "card_id";
            if (StringUtils.equals(result.get("result").toString(),"1")) {
                String cCardId = result.get("card_id").toString();
                resultMap.put("card_id", cCardId);
            } else {
                resultMap.put("message", "同步失败！");
            }
        } catch (Exception e) {
            resultMap.put("success", false);
            resultMap.put("message", e);
            LCLogger.withException(e);
        }
        return resultMap;
    }

    /**
     * 查询图文消息列表（多图文只显示第一条）
     *
     * @author 路江
     * @date 2018-05
     * @param entity
     * @return
     */
    @Override
    public List<Article> queryByArticlesByExamplePage(Article entity) throws Exception {
        List<Article> articlesList = articlesMapper.queryByArticlesByExamplePage(entity);
        return articlesList;
    }

    @Override
    public int getCount(Article entity) throws Exception {
        return articlesMapper.getCount(entity);
    }

    /**
     * 根据OpenID列表群发
     *
     * @author 路江
     * @date 2018-05
     * @param articles
     * @return
     */
    @Override
    public Map<String, Object> sendArticles(Article articles) throws Exception {
        Map<String, Object> result = new HashMap<>(8);
        //得到微信公众号信息
        articles.setPageFlag(false);
        List<Article> articlesList = this.queryByExamplePage(articles);
        if (articlesList.size() < 1) {
            throw new ServiceException("WECHAT-003");
        }
        WxPlatform platform = new WxPlatform();
        platform.setId(articlesList.get(0).getWxId());
        platform = wxPlatformService.queryById(platform);
        //微信token 两小时刷新
        String accessToken = wxTokenService.getWxAccessTokenByAppId(platform.getWx_app_id()).getAccess_token();
        String requestUrl = env.getProperty("weixinuri.sendallUrl").replace("ACCESS_TOKEN", accessToken);
        //组装json数据 以Map的形式
        if (articles.getOpenids().size() > 1) {
            Map<String, Object> dataMap = new HashMap<>(16);
            dataMap.put("touser",articles.getOpenids());
            Map<String, Object> mediaIdMap = new HashMap<>(16);
            mediaIdMap.put("media_id",articles.getMediaId());
            dataMap.put("mpnews",mediaIdMap);
            dataMap.put("msgtype","mpnews");
            dataMap.put("send_ignore_reprint",0);

            String currTime = PayUtils.getCurrTime();
            //8位日期
            String strTime = currTime.substring(8, currTime.length());
            //四位随机数
            String strRandom = PayUtils.buildRandom(4) + "";
            String nonceStr = strTime + strRandom;
            dataMap.put("clientmsgid",nonceStr);
            //Map数据转为json
            Gson gson = new Gson();
            // 转换成特定格式字符串
            String data = gson.toJson(dataMap);
            JSONObject dataJosn = WeixinHttpUtil.httpRequest(requestUrl,"POST",data);
            if (null != dataJosn) {
                Integer errcode = dataJosn.getInteger("errcode");
                if (0 == errcode) {
                    for (String openid : articles.getOpenids()) {
                        //存储消息记录
                        insertMessgeResult(platform, openid, articles.getId(), dataJosn);
                    }
                    result.put("success",true);
                } else {
                    throw new ServiceException("PUBLIC-037");
                }
            }
        } else if (articles.getOpenids().size() == 1) {
            throw new ServiceException("WECHAT-004");
        }
        return result;
    }

    /**
     * 存储到消息记录表里面
     *
     * @author 路江
     * @date 2018-05
     * @param platform 公众号信息
     * @param openid openid
     * @param mediaId 素材id
     * @param json
     * @throws Exception
     */
    private void insertMessgeResult(WxPlatform platform, String openid,Long mediaId,JSONObject json)
            throws Exception {
        Messageresult mResult = new Messageresult();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mResult.setTouser(openid);
        mResult.setDate(formatter.format(new Date()));
        mResult.setContent(String.valueOf(mediaId));
        mResult.setContentType("mpnews");
        mResult.setStatus("Succeeded");
        mResult.setType("Store");
        mResult.setResult(json.toString());
        mResult.setWxId(String.valueOf(platform.getId()));
        mResult.setFromUser(platform.getWx_og_id());
        mResult.setOpenid(openid);
        mResult.setWxusername(platform.getWx_og_id());
        messageresultService.insert(mResult);
    }

    /**
     * 查询满足发送图文条件的客户
     *
     * @author 路江
     * @date 2018-05
     * @param account 客户信息
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> queryAccountListByExamplePage(Account account) throws Exception {
        Map<String, Object> result = new HashMap<>(8);
        // 客户来源 门店客户
        account.setAcctChannel("Store");
        // 所属导购为当前登录导购
        // 已经关注了微信服务号
        // 获取当前导购
        account.setUserId(UserUtil.getUser().getId());
        account.setPageFlag(false);
        List<Account> list = accountMapper.queryAccountListByExamplePage(account);
        String order = "asc";
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Account acca = (Account) o1;
                Account accb = (Account) o2;
                if (order.equals(account.getAttr1())) {
                    return acca.getCreated().compareTo(accb.getCreated());
                } else {
                    return accb.getCreated().compareTo(acca.getCreated());
                }
            }
        });
        result.put("total",list.size());
        result.put("rows",list);
        return result;
    }

    @Override
    public List<NewsItem> getArticlesUrl(String jsonObject, String accessToken) throws Exception {
        Map<String, Object> dataMap = new HashMap<>(16);
        dataMap.put("media_id",jsonObject);
        Gson gson = new Gson();
        String data = gson.toJson(dataMap);
        String url = GET_PERMANENT_MATERIAL_URL.replace("ACCESS_TOKEN", accessToken);
        JSONObject json = WeixinHttpUtil.httpRequest(url, "POST", data);
        List<NewsItem> itemList = new ArrayList<>();
        String newsItem = "news_item";
        if (null != json && null != json.getJSONArray(newsItem)) {
            itemList = JSONArray.parseArray(json.getJSONArray(newsItem).toString(),NewsItem.class);
        }
        return itemList;
    }

    /**
     * 批量修改图文消息
     * @author 路江
     * @param  list 图文list
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = ServiceException.class)
    @Override
    public Map<String, Object> updateArticlesList(List<Article> list) throws Exception {
        Map<String, Object> map = new HashMap<>(16);
        //提前校验
        if (list.size() < 1) {
            throw new ServiceException("WECHAT-005");
        }
        //获取公众号信息
        WxPlatform wxplatform = new WxPlatform();
        wxplatform.setId(list.get(0).getWxId());
        WxPlatform platform = wxPlatformService.queryById(wxplatform);
        map = articleService.updateArticles(platform.getWx_app_id(),list);
        //批量修改存储的数据
        if (StringUtils.equals(map.get("result").toString(),"1")) {
            for (Article entity :list) {
                articlesMapper.update(entity);
            }
        }
        return map;
    }

    @Override
    public Map<String, Object> insertArticlesList(List<Article> entitys) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>(16);
        if (entitys.isEmpty()) {
            throw new ServiceException("WECHAT-006");
        }
        //保证图文标题的唯一性
        for (int i = 0; i < entitys.size(); i++) {
            Article articles = new Article();
            articles.setTitle(entitys.get(i).getTitle());
            articles.setWxId(entitys.get(i).getWxId());
            articles.setPageFlag(false);
            List<Article> articleslist = articlesService.queryByExamplePage(articles);
            if (articleslist.size() > 0) {
                map.put("success", false);
                map.put("msg", "素材标题已经存在:" + entitys.get(i).getTitle());
                return map;
            }
        }
        // 获取token
        WxPlatform wxplatform = new WxPlatform();
        wxplatform.setId(entitys.get(0).getWxId());
        WxPlatform platform = wxPlatformService.queryById(wxplatform);
        String accessToken = wxTokenService.getWxAccessTokenByAppId(platform.getWx_app_id()).getAccess_token();
        // 上传图文信息
        map = articleService.uploadArticles(platform.getWx_app_id(),entitys);
        String jsonObject = "jsonObject";
        if (null != map.get(jsonObject)) {
            //查询出图文消息路径
            List<NewsItem> items = articlesService.getArticlesUrl(map.get("jsonObject").toString(),accessToken);
            for (int i = 0; i < entitys.size(); i++) {
                entitys.get(i).setMediaId(map.get("jsonObject").toString());
                entitys.get(i).setResult(map.get("jsonObject").toString());
                for (NewsItem newsItem : items) {
                    if (newsItem.getTitle().equals(entitys.get(i).getTitle())) {
                        entitys.get(i).setArticlesUrl(newsItem.getUrl());
                    }
                }
                articlesService.insert(entitys.get(i));
            }
        }
        String mes = "success";
        //判断是保存还是保存并群发
        String message = "保存并群发";
        if (message.equals(entitys.get(0).getAttr5())) {
            mes = messageresultService.allSendMpnews(Long.valueOf(map.get("jsonObject").toString()), platform, entitys.get(0).getAttr6());
        }
        map.put("mes", mes);
        map.put("result", map.get("jsonObject"));
        map.put("success", true);
        return map;
    }

    @Override
    public Map<String, Object> deleteArticles(Article entity) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>(8);
        entity = articlesService.queryById(entity.getId());
        // 逻辑删除
        entity.setDeleteFlag("Y");
        super.update(entity);
        return map;
    }

    @Override
    public List<Article> queryByGroupId(Article article) throws Exception {
        return articlesMapper.queryByGroupId(article);
    }

}
